<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html;charset=utf-8">
  <title>file.pp</title>
  <link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
</head>
<body>
<div id='container'>
  <div id="background"></div>
  <div id="jump_to">
    Jump To &hellip;
    <div id="jump_wrapper">
      <div id="jump_page">
          <a class="source" href="deploy.html">deploy.pp</a>
          <a class="source" href="extract.html">extract.pp</a>
          <a class="source" href="file.html">file.pp</a>
          <a class="source" href="init.html">init.pp</a>
      </div>
    </div>
  </div>
  <table cellspacing=0 cellpadding=0>
  <thead>
    <tr>
      <th class=docs><h1>file.pp</h1></th>
      <th class=code></th>
    </tr>
  </thead>
  <tbody>
    <tr id='section-Define:_staging::file'>
      <td class=docs>
        <div class="pilwrap">
          <a class="pilcrow" href="#section-Define:_staging::file">&#182;</a>
        </div>
        <h3>Define: staging::file</h3>

<h4>Overview:</h4>

<p>Define resource to retrieve files to staging directories. It is
intententionally not replacing files, as these intend to be large binaries
that are versioned.</p>

<h4>Notes:</h4>

<p>  If you specify a different staging location, please manage the file
  resource as necessary.</p>

<h3>Parameters:</h3>

<ul>
<li>[<em>source</em>]:  the source file location, supports local files, puppet://, http://, https://, ftp:// (default: )</li>
<li>[<em>target</em>]:  the target staging directory, if unspecified ${staging::path}/${caller_module_name} (default: undef)</li>
<li>[<em>username</em>]:  https or ftp username (default: undef)</li>
<li>[<em>certificate</em>]:  https certificate file (default: undef)</li>
<li>[<em>password</em>]:  https or ftp user password or https certificate password (default: undef)</li>
<li>[<em>environment</em>]:  environment variable for settings such as http_proxy, https_proxy, of ftp_proxy (default: undef)</li>
<li>[<em>timeout</em>]:  the the time to wait for the file transfer to complete (default: undef)</li>
<li>[<em>subdir</em>]:  (default: $caller_module_name)</li>
</ul>


<h3>Usage:</h3>

<pre><code>$caller_module_name = 'demo'

class { 'staging':
  path =&gt; '/tmp/staging',
}

staging::file { 'sample':
  source =&gt; 'puppet:///modules/staging/sample',
}

staging::file { 'passwd':
  source =&gt; '/etc/passwd',
}

staging::file { 'manpage.html':
  source =&gt; 'http://curl.haxx.se/docs/manpage.html',
}
</code></pre>

      </td>
      <td class=code>
        <div class='highlight'><pre><span class="n">define</span> <span class="n">staging</span><span class="o">::</span><span class="n">file</span> <span class="p">(</span>
  <span class="vg">$source</span><span class="p">,</span>              
  <span class="vg">$target</span>      <span class="o">=</span> <span class="k">undef</span><span class="p">,</span> 
  <span class="vg">$username</span>    <span class="o">=</span> <span class="k">undef</span><span class="p">,</span> 
  <span class="vg">$certificate</span> <span class="o">=</span> <span class="k">undef</span><span class="p">,</span> 
  <span class="vg">$password</span>    <span class="o">=</span> <span class="k">undef</span><span class="p">,</span> 
  <span class="vg">$environment</span> <span class="o">=</span> <span class="k">undef</span><span class="p">,</span> 
  <span class="vg">$timeout</span>     <span class="o">=</span> <span class="k">undef</span><span class="p">,</span> 
  <span class="vg">$subdir</span>      <span class="o">=</span> <span class="vg">$caller_module_name</span>
<span class="p">)</span> <span class="p">{</span>

  <span class="kp">include</span> <span class="n">staging</span>

  <span class="k">if</span> <span class="vg">$target</span> <span class="p">{</span>
    <span class="vg">$target_file</span> <span class="o">=</span> <span class="vg">$target</span>
    <span class="vg">$staging_dir</span> <span class="o">=</span> <span class="n">staging_parse</span><span class="p">(</span><span class="vg">$target</span><span class="p">,</span> <span class="s1">&#39;parent&#39;</span><span class="p">)</span>
  <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
    <span class="vg">$staging_dir</span> <span class="o">=</span> <span class="s2">&quot;${staging::path}/${subdir}&quot;</span>
    <span class="vg">$target_file</span> <span class="o">=</span> <span class="s2">&quot;${staging_dir}/${name}&quot;</span>

    <span class="k">if</span> <span class="o">!</span> <span class="n">defined</span><span class="p">(</span><span class="no">File</span><span class="o">[</span><span class="vg">$staging_dir</span><span class="o">]</span><span class="p">)</span> <span class="p">{</span>
      <span class="n">file</span> <span class="p">{</span> <span class="vg">$staging_dir</span><span class="p">:</span>
        <span class="k">ensure</span><span class="o">=&gt;</span><span class="n">directory</span><span class="p">,</span>
      <span class="p">}</span>
    <span class="p">}</span>
  <span class="p">}</span>

  <span class="no">Exec</span> <span class="p">{</span>
    <span class="n">path</span>        <span class="o">=&gt;</span> <span class="s1">&#39;/usr/local/bin:/usr/bin:/bin&#39;</span><span class="p">,</span>
    <span class="n">environment</span> <span class="o">=&gt;</span> <span class="vg">$environment</span><span class="p">,</span>
    <span class="n">cwd</span>         <span class="o">=&gt;</span> <span class="vg">$staging_dir</span><span class="p">,</span>
    <span class="n">creates</span>     <span class="o">=&gt;</span> <span class="vg">$target_file</span><span class="p">,</span>
    <span class="n">timeout</span>     <span class="o">=&gt;</span> <span class="vg">$timeout</span><span class="p">,</span>
    <span class="n">logoutput</span>   <span class="o">=&gt;</span> <span class="n">on_failure</span><span class="p">,</span>
  <span class="p">}</span>

  <span class="k">case</span> <span class="vg">$source</span> <span class="p">{</span>
    <span class="sr">/^\//</span><span class="p">:</span> <span class="p">{</span>
      <span class="n">file</span> <span class="p">{</span> <span class="vg">$target_file</span><span class="p">:</span>
        <span class="n">source</span>  <span class="o">=&gt;</span> <span class="vg">$source</span><span class="p">,</span>
        <span class="n">replace</span> <span class="o">=&gt;</span> <span class="kp">false</span><span class="p">,</span>
      <span class="p">}</span>
    <span class="p">}</span>

    <span class="sr">/^puppet:\/\//</span><span class="p">:</span> <span class="p">{</span>
      <span class="n">file</span> <span class="p">{</span> <span class="vg">$target_file</span><span class="p">:</span>
        <span class="n">source</span>  <span class="o">=&gt;</span> <span class="vg">$source</span><span class="p">,</span>
        <span class="n">replace</span> <span class="o">=&gt;</span> <span class="kp">false</span><span class="p">,</span>
      <span class="p">}</span>
    <span class="p">}</span>

    <span class="sr">/^http:\/\//</span><span class="p">:</span> <span class="p">{</span>
      <span class="nb">exec</span> <span class="p">{</span> <span class="vg">$target_file</span><span class="p">:</span>
        <span class="n">command</span>     <span class="o">=&gt;</span> <span class="s2">&quot;curl -L -o ${name} ${source}&quot;</span><span class="p">,</span>
      <span class="p">}</span>
    <span class="p">}</span>

    <span class="sr">/^https:\/\//</span><span class="p">:</span> <span class="p">{</span>
      <span class="k">if</span> <span class="vg">$username</span> <span class="p">{</span>
        <span class="vg">$command</span> <span class="o">=</span> <span class="s2">&quot;curl -L -o ${name} -u ${username}:${password} ${source}&quot;</span>
      <span class="p">}</span> <span class="k">elsif</span> <span class="vg">$certificate</span> <span class="p">{</span>
        <span class="vg">$command</span> <span class="o">=</span> <span class="s2">&quot;curl -L -o ${name} -E ${certificate}:${password} ${source}&quot;</span>
      <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
        <span class="vg">$command</span> <span class="o">=</span> <span class="s2">&quot;curl -L -o ${name} ${source}&quot;</span>
      <span class="p">}</span>

      <span class="nb">exec</span> <span class="p">{</span> <span class="vg">$target_file</span><span class="p">:</span>
        <span class="n">command</span>     <span class="o">=&gt;</span> <span class="vg">$command</span><span class="p">,</span>
      <span class="p">}</span>
    <span class="p">}</span>

    <span class="sr">/^ftp:\/\//</span><span class="p">:</span> <span class="p">{</span>
      <span class="k">if</span> <span class="vg">$username</span> <span class="p">{</span>
        <span class="vg">$command</span> <span class="o">=</span> <span class="s2">&quot;curl -o ${name} -u ${username}:${password} ${source}&quot;</span>
      <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
        <span class="vg">$command</span> <span class="o">=</span> <span class="s2">&quot;curl -o ${name} ${source}&quot;</span>
      <span class="p">}</span>

      <span class="nb">exec</span> <span class="p">{</span> <span class="vg">$target_file</span><span class="p">:</span>
        <span class="n">command</span>     <span class="o">=&gt;</span> <span class="vg">$command</span><span class="p">,</span>
      <span class="p">}</span>
    <span class="p">}</span>

    <span class="n">default</span><span class="p">:</span> <span class="p">{</span>
      <span class="nb">fail</span><span class="p">(</span><span class="s2">&quot;stage::file: do not recognize source ${source}.&quot;</span><span class="p">)</span>
    <span class="p">}</span>
  <span class="p">}</span>

<span class="p">}</span></pre></div>
      </td>
    </tr>
  </table>
</div>
</body>
